import datetime
ADB_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S' # data format of read out from database
ADB_DATETIME_FORMAT2 = '%m/%d/%y %H:%M:%S'
ADB_CLOCK_FORMAT = '%H:%M:%S'
def getNowDate():
    str = datetime.datetime.now().strftime(ADB_DATETIME_FORMAT)
    return str

def getNowTime():
    str = datetime.datetime.now().strftime(ADB_CLOCK_FORMAT)
    return str

def str2Date(str, format=ADB_DATETIME_FORMAT):
    if '-' in str:
        return datetime.datetime.strptime(str, ADB_DATETIME_FORMAT)
    else:
        return datetime.datetime.strptime(str, ADB_DATETIME_FORMAT2)

def str2time(str, format=ADB_CLOCK_FORMAT):
    return str2Date(str, format).time()

def strDateDelta(strtime1, strtime2, format=ADB_DATETIME_FORMAT):
    return (str2Date(strtime1,format)-str2Date(strtime2, format))

